﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;

public partial class captcha : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string karakterler = "1234567890QWERTYUIOPLKJHGFDSAZXCVBNMqazxswedcvfrtgbnhyujmkiolp";
        string cod = "";
        Random rnd = new Random();
        for (int i = 0; i < 8; i++)
            cod += karakterler[rnd.Next(0, karakterler.Length)].ToString();

        Session["Captcha"] = cod.ToUpper();
        Bitmap bmp = new Bitmap(120, 40);
        Graphics g = Graphics.FromImage(bmp);
        g.DrawString(cod, new Font("Georgia", 14), new SolidBrush(Color.YellowGreen), 0, 0);

        MemoryStream ms = new MemoryStream();
        bmp.Save(ms, ImageFormat.Png);
        g.Dispose();
        bmp.Dispose();
        ms.Close();
        ms.Dispose();
        Context.Response.BinaryWrite(ms.GetBuffer());
    }
}